#include "oled_app.h"

const uint8_t star_bmp_128_32[] =
{
    0x3F,0xBF,0xF1,0xD5,0xE0,0xE0,0xE2,0xE1,0xE1,0xE0,0xE1,0xA1,0xEB,0xCF,0xC7,0xBF,
    0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFB,
    0xFF,0xFF,0xFB,0xFC,0xFC,0x5C,0x4F,0x2D,0x04,0xA4,0xB6,0x92,0xBF,0xE1,0x49,0x4C,
    0x44,0x24,0x00,0x00,0x00,0x00,0x04,0x34,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x06,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x01,0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x09,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
    0x0C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0xF0,0x00,0x00,0x00,0x00,0x00,
    0x87,0xC3,0x9B,0xBF,0xFF,0x7F,0x1F,0xBF,0xFF,0xFF,0x7F,0x7E,0x7F,0x35,0x12,0x9B,
    0xFB,0xDF,0xFC,0xF0,0x01,0x03,0x01,0xED,0x3F,0xFE,0x7F,0x7F,0x1F,0x7F,0xF7,0x7F,
    0xBF,0xEF,0x2A,0x2A,0x1B,0x1F,0x35,0xF5,0xF5,0xB7,0xD4,0xF6,0xD2,0xD2,0xFA,0xFA,
    0xFA,0xB0,0xE8,0xC8,0x88,0xE0,0x20,0x10,0x19,0x10,0x10,0x30,0x60,0x80,0x00,0xE0,
    0xD8,0x4C,0xC6,0x92,0xC3,0x81,0x4D,0x81,0xC1,0x43,0x02,0x06,0x2C,0x38,0xE0,0x0E,
    0x12,0x02,0xF2,0xF4,0x9C,0x08,0x39,0x7B,0xC8,0xD8,0x18,0x30,0xE0,0x00,0x00,0x00,
    0x80,0x66,0x76,0x1C,0x7F,0xE8,0x98,0x10,0x30,0xC0,0x00,0x00,0xC0,0x20,0x30,0x18,
    0x08,0x0B,0x18,0x10,0x30,0xC0,0x00,0x00,0x00,0x80,0xD5,0x80,0x00,0x00,0x00,0x00,
    0x87,0xFE,0xFF,0xF9,0xFB,0xFF,0xFE,0xFE,0xF4,0xFD,0xDB,0xB9,0xA6,0x9F,0x2E,0xBF,
    0xFF,0xCF,0x7F,0x1F,0x00,0x80,0xF0,0xF4,0xFE,0xF7,0xEF,0xEC,0xBC,0xFC,0xDF,0x5E,
    0xDE,0xDA,0xBC,0xAA,0xF0,0x78,0x58,0x5C,0x5F,0x52,0xD7,0x9F,0x9F,0x9F,0x9F,0x3F,
    0x1D,0x19,0x0D,0x07,0x00,0x0E,0x08,0x10,0xD0,0x10,0x10,0x18,0x0C,0x03,0x00,0x0F,
    0x33,0x62,0xD6,0x86,0x8D,0xD9,0x0C,0x19,0x80,0x90,0x97,0x46,0x6A,0x3F,0x0F,0x00,
    0x00,0x00,0x0F,0x1D,0x3F,0x2F,0x3E,0x7C,0x38,0x38,0x71,0x78,0xAE,0x9C,0x98,0xF0,
    0x03,0x0E,0x18,0x10,0xB0,0x10,0x33,0x7E,0xFC,0x07,0x00,0x00,0x07,0x0C,0x18,0x10,
    0x20,0xE0,0x10,0x10,0x1C,0x07,0x00,0x00,0x01,0x03,0xDC,0x03,0x01,0x00,0x00,0x00,
    0xF9,0xFB,0xFF,0xA7,0x8F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x8F,0x0F,0xC7,0xE7,0xF3,
    0xFB,0xFC,0xF8,0xFE,0xFC,0xFE,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
    0xFD,0xFF,0xDE,0xFF,0xEF,0xFD,0x79,0xB3,0xB2,0xB2,0x22,0xE6,0x64,0x44,0xC5,0x81,
    0x81,0x01,0x01,0x01,0x01,0x02,0x02,0x0A,0x07,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x41,0x1B,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0xE0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x80,0x56,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x14,0x00,0x00,0x00,0x00,0x00,
};

const uint8_t hello_bmp_128_32[] =
{
    0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xE0,0x00,0x80,0xE0,0xE0,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0x20,0x00,0x00,0x00,0x60,0x60,0x60,0x60,
    0x60,0xE0,0xC0,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,
    0x00,0xE0,0xE0,0x00,0x00,0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,
    0x60,0x60,0x60,0x60,0xE0,0xE0,0x60,0x60,0x60,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,
    0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0x30,0x80,0x80,
    0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x80,0xF0,0x70,0x00,0x80,
    0xF0,0x70,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x80,0xE0,0x70,0xFC,0xFF,0x03,0x18,0xBC,0x8F,0x03,0xFB,0xFB,0x03,0x93,0xBF,
    0x0F,0x03,0x00,0x00,0x03,0xF3,0xFF,0x0F,0x83,0xFF,0x7E,0xC0,0xC0,0xC0,0xE0,0xFC,
    0xDE,0xC3,0xC1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0xFC,0xFF,0x0F,0x0C,
    0xCC,0xFF,0x3F,0x0C,0x0C,0xFC,0xFF,0x0F,0x0C,0x0C,0x00,0x00,0x00,0x00,0x7F,0x7F,
    0x66,0xE6,0xE6,0x7E,0x7F,0xE6,0xE6,0x66,0x66,0x7F,0x1F,0x00,0x00,0x00,0x00,0xFE,
    0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3C,0x1F,0x03,0x21,0x3F,0x1F,
    0x03,0x00,0x1C,0x3F,0x37,0x35,0x35,0x17,0x07,0x20,0x3C,0x1F,0x03,0x20,0x3C,0x1F,
    0x03,0x00,0x1C,0x3F,0x33,0x31,0x31,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x01,0xE0,0xFF,0x0F,0x70,0x7C,0x0F,0x03,0x80,0xFF,0x3F,0x00,0x0F,0xFF,
    0x60,0x00,0x00,0x00,0x83,0xCF,0x7C,0x3C,0xFF,0x43,0x80,0x80,0x00,0x80,0xFF,0x7F,
    0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0xF0,0xFF,0x1F,0x00,0x00,
    0x1F,0x1F,0x18,0x18,0x18,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x18,0x1C,0x8C,0xE6,
    0xFF,0x1D,0x00,0x00,0x80,0xFD,0xFF,0x06,0x0C,0x1C,0x08,0x00,0x00,0x80,0xDC,0x9F,
    0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xF8,0x80,0x60,0x30,0xF8,0xF8,0x80,
    0xE0,0x38,0x18,0xC0,0xF0,0x30,0x18,0x18,0xF8,0xF8,0x00,0x00,0xC0,0xF8,0x38,0x10,
    0x18,0x00,0xC0,0xF8,0x3F,0x07,0xC0,0xF0,0x30,0x18,0x18,0xF8,0xF8,0x3F,0x07,0x00,
    0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x03,0x07,0x06,0x07,0x03,0x00,0x00,0x00,0x00,
    0x00,0x00,0x02,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x03,0x07,0x06,0x07,0x03,0x00,
    0x00,0x00,0x20,0x30,0x08,0x0F,0x07,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,
    0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x02,0x07,0x03,0x01,
    0x00,0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x01,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x01,0x00,0x00,0x03,0x03,0x03,
    0x00,0x00,0x00,0x01,0x03,0x03,0x03,0x03,0x01,0x00,0x00,0x02,0x03,0x01,0x00,0x00,
    0x00,0x02,0x03,0x01,0x00,0x00,0x03,0x03,0x03,0x01,0x03,0x03,0x01,0x00,0x00,0x00,
};

void oled_app_process(void)
{
    static bool inited = false;
    if(!inited) {
        oled_init();
        inited = true;
    }

#if 0
    oled_fill(0x00);
    oled_refresh();
    oled_delay_ms(100);
    oled_fill(0xF0);
    oled_refresh();
    oled_delay_ms(100);
    oled_fill(0xCC);
    oled_refresh();
    oled_delay_ms(100);
    oled_fill(0xAA);
    oled_refresh();
    oled_delay_ms(100);
    oled_fill(0xFF);
    oled_refresh();
    oled_delay_ms(100);

    oled_display_off();
    oled_delay_ms(500);
    oled_display_on();
    oled_delay_ms(500);

    oled_clear();
    oled_refresh();
    oled_delay_ms(500);

    for (uint8_t i = 0; i <= OLED_WIDTH; i += 8) {
        oled_draw_point(i == 0 ? 0 : i - 1, i == 0 ? 0 : ((i - 1) % OLED_HEIGHT));
        oled_refresh();
        oled_delay_ms(10);
    }

    oled_clear();
    for (uint8_t i = 0; i <= OLED_WIDTH; i += 8) {
        oled_draw_line(0, 0, i == 0 ? 0 : i - 1, OLED_HEIGHT - 1);
        oled_refresh();
        oled_delay_ms(10);
    }

    oled_color_reverse(true);
    oled_delay_ms(500);
    oled_color_reverse(false);
    oled_delay_ms(500);

    oled_clear();
    for (uint8_t i = 0; i <= OLED_WIDTH / 2; i += 8) {
        oled_draw_circle(OLED_WIDTH / 2 - 1, OLED_HEIGHT / 2 - 1, i);
        oled_refresh();
        oled_delay_ms(10);
    }

    oled_clear();
    oled_show_string(0, 0, "Hello World by HuangZY", 16);
    oled_refresh();
    oled_delay_ms(200);

    oled_show_string(0, 32, "2025-02-23", 16);
    oled_refresh();
    oled_delay_ms(200);

    oled_show_char(0, 48, 'A', 16);
    oled_refresh();
    oled_delay_ms(200);

    oled_show_num(64, 48, 21, 4, 16);
    oled_refresh();
    oled_delay_ms(200);

    oled_clear();
    oled_show_pic(0, 0, 128, 32, hello_bmp_128_32);
    oled_show_pic(0, 32, 128, 32, star_bmp_128_32);
    oled_refresh();
    oled_delay_ms(1000);

    oled_clear();
    oled_refresh();
    oled_delay_ms(1000);

    oled_show_pic_extend(0, 0, 128, 32, hello_bmp_128_32);
    oled_delay_ms(1000);
    oled_show_pic_extend(0, 32, 128, 32, star_bmp_128_32);
    oled_delay_ms(1000);

    oled_clear();
    oled_refresh();
    oled_delay_ms(1000);
#else
    uint8_t center_x = OLED_WIDTH / 2;
    uint8_t center_y = OLED_HEIGHT / 2;
    uint8_t side_len = 20;
    uint8_t speed_x = 10;
    uint8_t speed_y = 5;
    while (1) {
        oled_clear();
        oled_anim_cube(center_x, center_y, side_len, speed_x, speed_y);
        oled_refresh();
    }
#endif
}